﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using xTeam.HengLe.Entity;
using Valor.Helper;

namespace xTeam.HengLe.Controller.Website
{
    public class ProductController : BaseController
    {
        /// <summary>
        /// 
        /// </summary>
        public ActionResult Index(int classId = 0)
        {
            return RedirectToAction("List", new { classId = classId });
        }

        /// <summary>
        /// 
        /// </summary>
        public ActionResult List(int pageIndex = 1, int classId = 0)
        {
            int pageCount = 0;
            ProductViewModel viewModel = new ProductViewModel();
            EClassify classify = _classifyDataAccess.GetClassifyById(classId) ?? new EClassify() { Title = "所有产品" };
            viewModel.ImageRoot = _imageRoot;
            viewModel.ProductList = _productDataAccess.Search(8, pageIndex, classId, string.Empty, ref pageCount);
            viewModel.Classify = classify;
            ViewData["Pager"] = this.CreatePager(Url.Action("List", new { pageIndex = "{0}", classId = classId }),pageCount,pageIndex);
            return View(viewModel);
        }
        /// <summary>
        /// 
        /// </summary>
        public ActionResult Preview(int productId = 0)
        {
            EProduct product = _productDataAccess.GetBaseById(productId);
            if (product == null)
                return Content("Sorry Not Found !");
            ProductViewModel viewModel = new ProductViewModel() { ImageRoot = _imageRoot };
            viewModel.ProductView = product;
            viewModel.Details = _productDataAccess.GetDeatails(productId);
            viewModel.ImageList = _productDataAccess.GetImageList(productId);
            return View(viewModel);
        }
    }
}
